home *** CD-ROM | disk | FTP | other *** search
- //: C21:copy_if.h
- // From Thinking in C++, 2nd Edition
- // Available at http://www.BruceEckel.com
- // (c) Bruce Eckel 1999
- // Copyright notice in Copyright.txt
- // Roll your own STL-style algorithm
- #ifndef COPY_IF_H
- #define COPY_IF_H
-
- template<typename ForwardIter,
- typename OutputIter, typename UnaryPred>
- OutputIter copy_if(ForwardIter begin, ForwardIter end,
- OutputIter dest, UnaryPred f) {
- while(begin != end) {
- if(f(*begin))
- *dest++ = *begin;
- begin++;
- }
- return dest;
- }
- #endif // COPY_IF_H ///:~
-